package com.MovieManageSystem.service.implement;

import com.MovieManageSystem.domain.Comment;
import com.MovieManageSystem.mapper.CommentMapper;
import com.MovieManageSystem.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public void submitComment(Comment comment) {
        commentMapper.insertComment(comment);
    }

    @Override
    public List<Comment> getCommentsByMovieId(Integer vid) {
        return commentMapper.findByMovieVid(vid);
    }

    @Override
    public void deleteCommentByCid(Integer cid) {
        commentMapper.deleteCommentByCid(cid);
    }

    @Override
    public List<Comment> getAllComments() {
        List<Comment> comments = commentMapper.findAllComments();
        for (Comment comment : comments) {
            comment.setVidFromMovie(); // 设置 vid
        }
        return comments;
    }

    @Override
    public List<Comment> getCommentList() {
        return commentMapper.getCommentList();
    }
}
